package com.test.realcityalfa;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.actionbarsherlock.app.ActionBar;
import com.test.realcityalfa.actionbar.ActionBarBuilder;
import com.test.realcityalfa.actionbar.ActionBarSettings;
import com.test.realcityalfa.activityswitchers.ActivitySwitch;
import com.test.realcityalfa.frmwrk.BaseActivity;
import com.test.realcityalfa.frmwrk.CommercialDownloaderAsyncTask;

public class CommercialActivity extends BaseActivity
{
	ImageView commercialImage;
	ProgressBar commercialProgress;
	ActivitySwitch activitySwitch;
	CommercialDownloaderAsyncTask commercialDownloader;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(com.test.realcityalfa.R.layout.commercial_activity);
		
		ActionBarBuilder barBuilder = new ActionBarBuilder(this);
		ActionBarSettings barSettings = new ActionBarSettings();
		barSettings.setVisibility(false);		
		ActionBar bar = barBuilder.createActionBar();
		barBuilder.applyActionBarSettings(bar, barSettings);
		
		this.commercialDownloader = new CommercialDownloaderAsyncTask(this, (ProgressBar) findViewById(R.id.commercialProgress), Constants.Commercial.COMMERCIAL_URL);
		commercialDownloader.execute();		
		
	}
	
	
	
	@Override
	protected void onResume() 
	{
		//this.commercialDownloader = new CommercialDownloaderAsyncTask(this, (ProgressBar) findViewById(R.id.commercialProgress), Constants.Commercial.COMMERCIAL_URL);
		if(this.commercialDownloader.getStatus() == AsyncTask.Status.FINISHED)
		{
			Log.d(getClass().getName(), "AsyncTask was already finished");
			new ActivitySwitch(DashboardActivity.class).goToNextActivity(this, 0);
		}
		super.onResume();
	}



	@Override
	protected void onStop() 
	{
		this.commercialDownloader.cancelTask();
		super.onStop();
	}


	
	@Override
	protected void onDestroy() 
	{
		this.commercialDownloader.cancelTask();
		super.onDestroy();
	}
	


	public void testClick(View v)
	{
		goToNextActivity();
	}
	
	private void getViews()
	{
		commercialImage = (ImageView) findViewById(R.id.commercialImage);
		commercialProgress = (ProgressBar) findViewById(R.id.commercialProgress);
	}
	
	
	private void goToNextActivity()
	{		
		startActivity(new Intent(getApplicationContext(), DashboardActivity.class));
		finish();
	}		
}
